home *** CD-ROM | disk | FTP | other *** search
- /*
- dshell v3
-
- CUTファイル表示関連
- */
-
- #include "dsh.h"
-
-
- static int expand1(uchar *, int, uchar *);
- static int expand2(uchar *, int, uchar *);
- static void nega_posi(uchar *, int, uchar);
-
- static uchar loadingBgCutFlag = FALSE;
-
- /*
- 1 総バイト数
- BUF_X / 8 圧縮フラグのMAX
- BUF_X 非圧縮部のビットパターンのMAX
- */
- typedef uchar CONDBUF[1 + BUF_X / 8 + BUF_X];
-
-
-
- /*
- CUTファイルのヘッダー読み込み
-
- 戻り値:
- 必要なバッファサイズ(0の時はエラー)
- */
- int
- cut_read_header(FILE *fp, CUT *cut)
- {
- short cut_size;
- char cut_header[96];
- char type;
-
- switch (cut->type) {
- case CUTFILE:
- if (fread(cut_header, sizeof(char), 48 + 2 + 2, fp) != 48 + 2 + 2) {
- cut->type = -1;
- return 0;
- }
- break;
- case TITLESYS:
- if (fread(cut_header, sizeof(char), 48 + 16 + 2 + 2, fp) != 48 + 16 + 2 + 2) {
- cut->type = -1;
- return 0;
- }
- break;
- default:
- cut->type = -1;
- fread(cut_header, sizeof(char), 48, fp); /* ヘッダー文字列読み込み */
-
- if (*cut_header == 0) {
- fread(cut_header, sizeof(char), 16, fp);
- type = TITLESYS;
- #if 0
- } else if ((*cut_header == 'C') || (strncmp(cut_header, "CUT_V", 5) == 0)) {
- #else
- } else if (*cut_header == 'C') {
- #endif
- type = CUTFILE;
- } else {
- return 0;
- }
- fread(&cut_size, 2, 1, fp);
- if (cut_size <= 0)
- return 0;
- cut->x = cut_size; /* X方向ドット数(上位2バイト) */
- fread(&cut_size, 2, 1, fp);
- #define CUTLINEMAX (0x7f - 0x20)
- if (cut_size <= 0 || cut_size > CUTLINEMAX * 16)
- return 0;
- cut->y = cut_size; /* Y方向ドット数(下位2バイト) */
- cut->type = type;
- break;
- }
-
- return byteCount(cut->x) * cut->y /* データ本体バッファサイズ */
- + lineCount(cut->y) * 4; /* 各行カット縦横サイズ格納分 */
- }
-
- /*
- カットファイル本体読み込み
- (逐次読み込み、展開)
- */
- int
- cut_read2(FILE *fp, CUT *cut)
- {
- int size, y, by; /* bit-Y */
-
- CONDBUF cond1, cond2;
- uchar *buffer;
- TEXTBUF *now_ptr;
-
- now_ptr = cut->ptr;
- size = byteCount(cut->x);
- /*
- まず expand2内のバッファをクリアしておく
- (一番最初のラインの一つ前のラインを疑似的に作る)
- 渡す buffer, cond2 はダミー
- */
- expand2(NULL, 0, NULL);
-
- for (y = 0, by = 0; y < cut->y; y++) {
- if (by == 0) {
- now_ptr->dx = cut->x;
- now_ptr->dy = BUF_Y;
- buffer = &now_ptr->buffer[0][0];
- }
- /*
- 先頭1バイト(圧縮後の1ラインの総バイト数)の
- 読み込みとチェック
- */
- if (fread(cond1, 1, 1, fp) < 1) {
- break;
- }
- /*
- 続いて数バイトの圧縮フラグと、
- 非圧縮の部分のビットイメージデータ列の
- 読み込みとチェック
- */
- if (fread(cond1 + 1, sizeof(char), (*cond1) - 1, fp) < *cond1 - 1) {
- break;
- }
-
- expand1(cond2, size, cond1);
- expand2(buffer, size, cond2);
- buffer += size;
- if (++by == BUF_Y) {
- by = 0;
- now_ptr = (TEXTBUF *) buffer;
- }
- }
- if (by != 0) {
- now_ptr->dy = by;
- }
- return 0;
- }
-
-
- /*
- カットファイル本体読み込み
- (一括読み込み後の展開)
- */
- int
- cut_read(char *cut_ptr2, CUT *cut) /* TEXTBUF *cut_ptr, int cut_x, int cut_y) */
- {
- int size, y, by;
-
- CONDBUF cond2;
- char *cond1;
- uchar *buffer;
- TEXTBUF *now_ptr;
-
- cond1 = cut_ptr2;
- now_ptr = cut->ptr;
- size = byteCount(cut->x);
- /*
- expand2()内のバッファ初期化
- 渡す buffer, cond2 はダミー
- */
- expand2(NULL, 0, NULL);
- for (y = 0, by = 0; y < cut->y; y++) {
- if (by == 0) {
- now_ptr->dx = cut->x;
- now_ptr->dy = BUF_Y;
- buffer = &now_ptr->buffer[0][0];
- }
- expand1(cond2, size, cond1);
- expand2(buffer, size, cond2);
- buffer += size;
- if (++by == BUF_Y) {
- by = 0;
- now_ptr = (TEXTBUF *) buffer;
- }
- cond1 += *cond1;
- }
- if (by != 0) {
- now_ptr->dy = by;
- }
- return 0;
- }
-
- /*
- TITLE.SYSフォーマットデータ
- (逐次読み込み、展開)
- */
- int
- ttl_read2(FILE *fp, CUT *cut) /* TEXTBUF *cut_ptr, int cut_x, int cut_y) */
- {
- int size, y, by;
- uchar *buffer;
- TEXTBUF *now_ptr;
-
- now_ptr = cut->ptr;
- size = byteCount(cut->x);
- for (y = 0, by = 0; y < cut->y; y++) {
- if (by == 0) {
- now_ptr->dx = cut->x;
- now_ptr->dy = BUF_Y;
- buffer = &now_ptr->buffer[0][0];
- }
- if (fread(buffer, sizeof(char), size, fp) < size) {
- break;
- }
-
- buffer += size;
- if (++by == BUF_Y) {
- by = 0;
- now_ptr = (TEXTBUF *) buffer;
- }
- }
- if (by != 0) {
- now_ptr->dy = by;
- }
- return 0;
- }
-
-
- /*
- TITLE.SYSフォーマットデータ
- (一括読み込み後の展開)
- */
- int
- ttl_read(char *cut_ptr2, CUT *cut) /* TEXTBUF *cut_ptr, int cut_x, int cut_y) */
- {
- int size, x, y, by;
- char *cond1;
- uchar *buffer;
- TEXTBUF *now_ptr;
-
- cond1 = cut_ptr2;
- now_ptr = cut->ptr;
- size = byteCount(cut->x);
- for (y = 0, by = 0; y < cut->y; y++) {
- if (by == 0) {
- now_ptr->dx = cut->x;
- now_ptr->dy = BUF_Y;
- buffer = &now_ptr->buffer[0][0];
- }
- for (x = 0; x < size; x++) {
- *buffer++ = *cond1++;
- }
- if (++by == BUF_Y) {
- by = 0;
- now_ptr = (TEXTBUF *) buffer;
- }
- }
- if (by != 0) {
- now_ptr->dy = by;
- }
- return 0;
- }
-
-
- /*
- 圧縮フラグによるデータ展開
-
- org:元データ
- cond:展開後データ
- count:展開後のデータの大きさ
- */
- static int
- expand1(uchar *org, int count, uchar *cond)
- {
- int pt, bt, flag;
- uchar *head, *body;
-
- if (*cond == 1) { /* 全圧縮の時 */
- for (pt = 0; pt < count; pt++) {
- *org++ = 0;
- }
- return (count);
- }
- pt = byteCount(count);
- body = (head = cond + 1) + pt; /* ビットイメージデータのポインタセット */
- for (; pt; pt--) {
- flag = *head++;
- for (bt = 8; bt; bt--) {
- if (flag & 0x80) {
- *org = *body++; /* 非圧縮データ */
- } else {
- *org = 0; /* 圧縮データ */
- }
- org++;
- flag <<= 1;
- }
- }
- return count;
- }
-
- /*
- XORによる展開
-
- org:展開後データ
- cond:元データ
- count:データの大きさ
- */
- static int
- expand2(uchar *org, int count, uchar *cond)
- {
- static LINEBUF org_buf;
- int c;
- uchar *buf;
-
- buf = org_buf;
- if (count == 0) { /* バッファの初期化(init)指定 */
- for (c = 0; c < BUF_X; c++) {
- *buf++ = 0;
- }
- } else { /* 実際にデータ展開 */
- for (c = 0; c < count; c++) {
- *org = *cond++ ^ *buf; /* 前ラインの対応ビットとのXOR */
- *buf++ = *org++;
- }
- }
- return count;
- }
-
- void
- d_cut_load(char *filnm)
- {
- w_mes(0, "カットファイルをロード中です");
- w_mes(1, filnm);
- w_mes(2, "しばらくお待ち下さい");
- /*
- ! w_mes(3," ");
- ! w_mes(4,Sysmes2);
- ! w_mes(5," + cut_file Loader ver1.0 By BEEPs ");
- */
- }
-
- int
- cut_print(int sx, int sy, CUT *cut, int cut_lno)
- {
- int x = 0, size;
- uchar *ptr;
-
- if (cut->ptr != NULL && cut_lno < lineCount(cut->y)) {
- uchar mask = 0;
- static const uchar maskPat[] = {
- 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01,
- };
-
- if (cutrev_Mode && (cut->flag & cutREVERSE))
- mask = maskPat[cut->x & (8 - 1)];
- x = byteCount(cut->x);
- size = x * BUF_Y;
- ptr = (uchar *)cut->ptr + (size + 4) * cut_lno;
- if (mask) { /* ハードコピー用に陰陽反転 */
- nega_posi(ptr + 4, x, mask);
- }
- TEXTPUT(sx, sy, (struct FNTBUF *)ptr);
- if (mask) { /* 反転を戻す */
- nega_posi(ptr + 4, x, mask);
- }
- }
- return x;
- }
-
- /*
- 陰陽反転表示のため、カットデータバッファの内容をビット反転する(一行分)
-
- x:横バイト数
- */
- static void
- nega_posi(uchar *ptr, int x, uchar maskpat)
- {
- int i, j;
-
- for (j = 0; j < BUF_Y; j++) {
- for (i = 1; i < x; i++) {
- *ptr++ ^= 0xff;
- }
- *ptr++ = *ptr ^ maskpat;
- }
- }
-
-
- /*
- カットファイルを読み込み
- データを内部バッファに展開する
-
- cut_no:カットファイル(名)バッファの格納開始番号(ポインタ:0~)
- */
- int
- cut_job_read(int cut_no)
- {
- FILE *fp;
- int cut_size;
- char *cut_ptr2; /* 一気読込モード時のバッファポインタ */
- int cut_first, cut_last;
-
- cut_first = cut_no; /* これから読むカットデータはここから… */
- for (cut_last = cut_no; cut_last < CUT_MAX && cut[cut_last].fname != NULL; cut_last++) ; /* …ここまで */
-
- for (; cut_no < CUT_MAX && cut[cut_no].fname != NULL; cut_no++) {
- if (!loadingBgCutFlag) {
- char mes[16];
-
- d_cut_load(cut[cut_no].fname);
-
- sprintf(mes, "%3d / %3d", cut_no - cut_first + 1, cut_last - cut_first);
- w_mes(3, mes);
- }
- cut[cut_no].ptr = NULL;
- if ((fp = fopen(cut[cut_no].fname, "rb")) == NULL) {
- if (!loadingBgCutFlag) {
- char bf[100];
-
- w_open();
- sprintf(bf, "%sがオープンできません", cut[cut_no].fname);
- w_mes(0, bf);
- w_mes(2, "処理を続けます");
- w_wait(100);
- }
- continue;
- }
- if ((cut_size = cut_read_header(fp, &(cut[cut_no]))) > 0) {
- cut[cut_no].ptr = (TEXTBUF *)MALLOC(cut_size);
- if ((int)cut[cut_no].ptr < 0) {
- cut[cut_no].ptr = NULL;
- } else {
- cut_size = dfilelength(fileno(fp));
- cut_ptr2 = (char *)MALLOC(cut_size);
- if ((int)cut_ptr2 < 0) {
- if (cut[cut_no].type == TITLESYS) {
- ttl_read2(fp, &(cut[cut_no]));
- } else if (cut[cut_no].type == CUTFILE) {
- cut_read2(fp, &(cut[cut_no]));
- }
- } else {
- fread(cut_ptr2, sizeof(char), cut_size, fp);
- if (cut[cut_no].type == TITLESYS) {
- ttl_read(cut_ptr2, &(cut[cut_no]));
- } else if (cut[cut_no].type == CUTFILE) {
- cut_read(cut_ptr2, &(cut[cut_no]));
- }
- if (MFREE(cut_ptr2) && !loadingBgCutFlag) {
- d_mfree();
- }
- }
- }
- }
- fclose(fp);
- }
-
- return (cut_no);
- }
-
-
- /*
- CUT ファイル名の解釈と対応する CUT 番号の取得
- */
- int
- getCutNo(uchar *p, uchar *cutPath, struct NAMECKBUF *fname, uchar **tail, uchar termChr)
- {
- uchar pflag = FALSE;
- uchar hflag = FALSE;
- uchar nflag = cutREVERSE;
- uchar dupFlag = FALSE;
- uchar c, cbak, *q = p;
- signed char alignMode = 0;
- int n;
-
- while ((c = *q++) > ' ' && c != termChr)
- ;
- q--;
- cbak = *q;
- *q = '\0';
- while (c = *p++) {
- if (c == '+') // ドキュメントファイルと同一パスから探す
- pflag = TRUE;
- else if (c == '-') // カットファイル名を表示しない
- hflag = TRUE;
- else if (c == '*') // イメージ印刷の際ネガポジ反転しない
- nflag = 0;
- else if (c == '?') { // 必要行数の %CUT を自動挿入する
- dupFlag = cutDUP;
- hflag = TRUE;
- } else if (c == '<') { // 左寄せ
- alignMode = -1;
- dupFlag = FALSE;
- hflag = TRUE;
- } else if (c == '>') { // 右寄せ
- alignMode = 1;
- dupFlag = FALSE;
- hflag = TRUE;
- } else
- break;
- }
- if (c == '\0' || NAMECK(--p, fname) != 0) {
- *q = cbak;
- return -1;
- }
- if (pflag) {
- char temp[256];
- strcpy(temp, cutPath);
- strcat(temp, p);
- NAMECK(temp, fname);
- }
- *q = cbak;
- if (hflag && tail != NULL) {
- if (cbak == termChr)
- q++;
- *tail = q;
- }
- strcat((char *)fname, fname->name);
- strcat((char *)fname, fname->ext);
- dstrupr((char *)fname);
-
- for (n = 0; n < CUT_MAX; n++) {
- if (cut[n].fname == NULL) {
- FILE *fp;
-
- cut[n].flag = (nflag | dupFlag);
- if (alignMode < 0)
- cut[n].flag |= cutLEFT;
- else if (alignMode > 0)
- cut[n].flag |= cutRIGHT;
- cut[n].type = -1;
- cut[n].fname = (char *)fname;
- if ((fp = fopen((char *)fname, "rb")) != NULL) {
- // ヘッダを読み、サイズを得る
- cut_read_header(fp, &cut[n]);
- fclose(fp);
- }
- if (tail == NULL)
- cut[n].flag &= cutREVERSE;
- cut[n].fname = NULL;
- return n;
- } else if (((cut[n].flag & nflag) == nflag) && cut[n].type >= 0
- && strEqu(cut[n].fname, (char *)fname)) {
- if (tail != NULL)
- cut[n].flag |= dupFlag;
- if (alignMode < 0)
- cut[n].flag |= cutLEFT;
- else if (alignMode > 0)
- cut[n].flag |= cutRIGHT;
- return n;
- }
- }
-
- dabort("カットファイル数が最大値を越えます");
- return -1;
- }
-
-
- int
- loadBgCut(uchar *fname)
- {
- struct NAMECKBUF temp;
-
- loadingBgCutFlag = TRUE; // メッセージウィンドウの抑制
- if (getCutNo(fname, ((struct PDBADR *)_PSP)->exe_path, &temp, NULL, ';') < 0)
- return -1;
- if ((fname = strdup(fname)) == NULL)
- return -1;
- cut[0].fname = fname;
- cut_job_read(Cut_Begin);
- if (cut[0].ptr == NULL)
- return -1;
- Cut_Begin++;
- loadingBgCutFlag = FALSE;
-
- return 0;
- }
-